package com.demo.word.model;

import lombok.Data;

/**
 * @author FanJiangFeng
 * @version 1.0.0
 * @ClassName DataBase.java
 * @Description TODO
 * @createTime 2020年04月23日 14:15:00
 */
@Data
public class DataBase {

//    private static String mysqlUrl="jdbc:mysql://[ip]:[port]/[db]?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC";
    private static String mysqlUrl="jdbc:mysql://[ip]:[port]/[db]?" +
        "useSSL=false&useUnicode=true&characterEncoding=utf8&autoReconnect=true" +
        "&rewriteBatchedStatements=TRUE&serverTimezone=Asia/Shanghai&allowMultiQueries=true" +
        "&useInformationSchema=true";
    private static String oracleUrl="jdbc:oracle:thin:@[ip]:[port]:[db]";

    private String dbType;//数据库类型
    private String userName;
    private String passWord;
    private String driver;
    private String url;

    public DataBase(){}
    public DataBase(String dbType){
        this(dbType,"127.0.0.1","3306","");
    }
    public DataBase(String dbType,String db){
        this(dbType,"127.0.0.1","3306",db);
    }
    /**
     *
     * @param dbType    数据库类型 mysql/oracle
     * @param ip        ip
     * @param port      3306
     * @param db        数据库名称 test
     */
    public DataBase(String dbType,String ip,String port,String db){
        this.dbType=dbType;
        if("MYSQL".equals(dbType.toUpperCase())){
            this.driver="com.mysql.cj.jdbc.Driver";
            this.url=mysqlUrl.replace("[ip]",ip).replace("[port]",port).replace("[db]",db);
        }else{
            this.driver="oracle.jdbc.driver.OracleDriver";
            this.url=oracleUrl.replace("[ip]",ip).replace("[port]",port).replace("[db]",db);
        }
    }



}

